package com.xiaotao.entity;

import lombok.Data;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Data
public class TeamPost {
    private Long id;
    private Integer userId;
    private String title;
    private String content;
    private String category;
    private Integer maxMembers = 10;
    private Integer currentMembers = 1;
    private String location;
    private Double latitude;
    private Double longitude;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private LocalDateTime startTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private LocalDateTime endTime;

    private String status = "招募中";
    private Integer viewCount = 0;
    private Integer likeCount = 0;
    private Integer applyCount = 0;
    private Integer recommendScore = 0;
    private String tags;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private LocalDateTime createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    private LocalDateTime updateTime;

    private Integer isDeleted = 0;

    // 关联查询字段
    private String nickname;
    private String avatar;
    private Integer credit;

    public List<String> getTagsAsList() {
        if (tags == null || tags.trim().isEmpty()) {
            return new ArrayList<>();
        }
        List<String> tagList = new ArrayList<>();
        for (String tag : tags.split(",")) {
            String trimmed = tag.trim();
            if (!trimmed.isEmpty()) {
                tagList.add(trimmed);
            }
        }
        return tagList;
    }

    public void setTagsFromList(List<String> tagList) {
        if (tagList == null || tagList.isEmpty()) {
            this.tags = "";
        } else {
            this.tags = String.join(",", tagList);
        }
    }
}